package cn.edu.zafu.bigdata.x.LiJuan;

import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int maxGuesses = 6; // 最大猜测次数
        Random random = new Random();
        int targetNumber = random.nextInt(100) + 1; // 随机数范围1-100

        System.out.println("欢迎参与猜数字游戏！");
        System.out.println("这里有一个1到100之间的数字，你有" + maxGuesses + "次机会猜中它。");

        for (int i = 1; i <= maxGuesses; i++) { //i为已经猜测的次数
            System.out.print("猜一猜: ");
            int userGuess = scanner.nextInt();

            if (userGuess == targetNumber) {
                System.out.println("真厉害！你猜对了数字是：" + targetNumber);
                break;
            } else if (userGuess < targetNumber) {
                System.out.println("你猜的数字小了。");
            } else if (userGuess > targetNumber) {
                System.out.println("你猜的数字大了。");
            }

            System.out.println("你还有 " + (maxGuesses - i) + " 次机会。");

            if (i == maxGuesses) {
                System.out.println("可惜没有猜中，你的猜测次数已用完。");
                System.out.println("正确的数字是：" + targetNumber);
            }
        }

        System.out.println("游戏结束，感谢你的参与！");
        scanner.close();
    }
}